import React from 'react'
// react-redux中引入useDispatch和useSelector方法
import {useDispatch,useSelector} from 'react-redux'
// 引入countSlice中暴露的方法
import { increment,decrement } from "../../store/slice/countSlice";

export default function Count() {
  // 获取dispatch方法
  const dispatch = useDispatch()
  // 获取store中的count数据
  const count = useSelector(state=>state.count.count)
  
  const increamentHandle=()=>{
    dispatch(increment(10))
  }
  const decreamentHandle=()=>{
    dispatch(decrement(5))
  }
  const ifevenIncreamentHandle=()=>{
    if(count%2===0){
      dispatch(increment(3))
    }
  }
  return (
    <div>
        <h1>我是count组件,我的值是{count}</h1>
        <h2>movie请求的电影数据是{}个</h2>
        <button onClick={increamentHandle}>累加</button>
        <button onClick={decreamentHandle}>累减</button>
        <button onClick={ifevenIncreamentHandle}>遇到偶数就加1</button>
    </div>
  )
}
